package com.zh.note.huawei.onehundred.数组去重和排序;

/**
 * @Author: zhanghuan
 * @date: 2023/9/4 14:48
 * @description: create it
 */

import java.util.*;

public class Main {

    public static void main(String[] args) {
        try {
            Scanner sca = new Scanner(System.in);
            // String input = sca.nextLine();
            String input = "1,3,3,3,2,4,4,4,5";
            String[] inputs = input.split(",");
            List<Integer> myList = new ArrayList<>();
            Map<Integer, Integer> myMap = new HashMap<>();
            for (String s : inputs) {
                int num = Integer.parseInt(s);
                if (!myList.contains(num)) {
                    myList.add(num);
                }
                myMap.put(num, myMap.getOrDefault(num, 0) + 1);
            }
            List<int[]> resList = new ArrayList<>();
            for (Integer i : myList) {
                int[] datas = new int[2];
                datas[0] = i;
                datas[1] = myMap.get(i);
                resList.add(datas);
            }
            // 排序
            resList.sort((a1, a2) -> Integer.compare(a2[1], a1[1]));

            for (int j = 0; resList.size() > j; ++j) {
                System.out.print(resList.get(j)[0]);
                if (resList.size() - 1 != j) {
                    System.out.print(",");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("input error");
        }

    }
}
